#include "pcap_packet.h"

Qpcap_packet::Qpcap_packet()
{
}
bool Qpcap_packet::setPcap_packet(ifstream  &infilestream)
{
    infilestream.read((char*)(&pcappacketheader),16);
    infilestream.read((char*)(&ethnetheader),14);
    if (ethnetheader.eth_type == 0x08)    /// if the ethnect type is  IP
    {
        infilestream.read((char*)(&ipheader),20);
        if (ipheader.ihl != 0x5)  /// if ipheader is not 0x05
        {
            infilestream.seekg((ipheader.ihl - 0x5)*4,ios_base::cur);
        }
        if (ipheader.protocol == 17)  /// if the transmission type is udp
        {
            infilestream.read((char*)(&udpheader),8);
            return true;
        }
        else if (ipheader.protocol == 6) /// if the transmission type is tcp
        {
            infilestream.read((char*)(&tcpheader),20);
            return true;
        }
        else return false;
    }
    else   /// if the ethnect type is not IP
    {
        return false;
    }
}

unsigned long Qpcap_packet::getPcap_packetcaplen()
{
    return pcappacketheader.caplen;
}

unsigned short Qpcap_packet::getMac_eth_type()
{
    return ethnetheader.eth_type;
}
unsigned char Qpcap_packet::getIP_Protocl_type()
{
    return ipheader.protocol;
}

